home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / blanker / source / blankers / clock / blank.c next >
C/C++ Source or Header  |  1993-08-15  |  4KB  |  148 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3.  
  4. #include <dos/dos.h>
  5. #include <dos/datetime.h>
  6.  
  7. #include <intuition/intuition.h>
  8. #include <intuition/screens.h>
  9.  
  10. #include <clib/exec_protos.h>
  11. #include <clib/graphics_protos.h>
  12. #include <clib/intuition_protos.h>
  13. #include <clib/dos_protos.h>
  14. #include <clib/diskfont_protos.h>
  15. #include <clib/utility_protos.h>
  16. #include <clib/alib_protos.h>
  17.  
  18. #include <stdio.h>
  19.  
  20. #include "Clock.h"
  21. #include "/defs.h"
  22. #include "/utility.h"
  23.  
  24. struct cPrefObject {
  25.     UBYTE fName[64], Speed, Cycle, Secs, Military;
  26.     struct TextAttr Font;
  27. };
  28.  
  29. extern    struct    cPrefObject    nP;
  30. extern          ULONG   Depth, Mode;
  31. extern          UBYTE   *prefData;
  32.     
  33. int getTime( UBYTE *time, struct cPrefObject *nP )
  34. {
  35.     struct    DateTime dt;
  36.     ULONG    h,m,s;
  37.  
  38.     CopyMem( DateStamp( &dt.dat_Stamp ), &dt.dat_Stamp, sizeof( struct DateStamp ));
  39.     dt.dat_StrDay = 0L;
  40.     dt.dat_StrDate = 0L;
  41.     dt.dat_StrTime = time;
  42.  
  43.     if( !DateToStr( &dt )) time[0] = 0;
  44.     else {
  45.         sscanf( time, "%d:%d:%d", &h, &m, &s );
  46.         if( nP->Military ) {
  47.             if( nP->Secs ) {
  48.                 sprintf( time, "%d:%02d:%02d", h, m, s );
  49.                 return(( h > 9 )?8:7 );
  50.             } else {
  51.                 sprintf( time, "%d:%02d", h, m );
  52.                 return(( h > 9 )?5:4 );
  53.             }
  54.         } else {
  55.             if( nP->Secs ) {
  56.                 sprintf( time, "%d:%02d:%02d%s", (!h?12:(h%13)+(h/13)), m, s, h>11?"pm":"am" );
  57.                 return(( h%13 > 8 )?10:9 );
  58.             } else {
  59.                 sprintf( time, "%d:%02d%s", (!h?12:(h%13)+(h/13)), m, h>11?"pm":"am" );
  60.                 return(( h%13 > 8 )?7:6 );
  61.             }
  62.         }
  63.     }
  64. }
  65.  
  66. VOID blank( VOID )
  67. {
  68.     struct    TextFont    *font;
  69.     struct    cPrefObject    *bP;
  70.     struct    Screen        *Scr;
  71.     UBYTE    vals[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4,
  72.         3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  73.     UBYTE    scrClock[128], c1 = 0, c2 = 14, c3 = 28;
  74.     ULONG    x, y, Wid, Hei, len, nlen, numc, base, count = 0;
  75.     LONG    dx = 1, dy = 1;
  76.  
  77.     if( ClockWnd ) bP = &nP;
  78.     else bP = ( struct cPrefObject * )prefData;
  79.  
  80.     bP->Font.ta_Name = bP->fName;
  81.     font = OpenDiskFont( &( bP->Font ));
  82.     base = font->tf_Baseline;
  83.  
  84.     Scr = OpenScreenTags( 0l, SA_DisplayID, Mode, SA_Depth, 1, SA_Quiet, TRUE, SA_Behind, TRUE, SA_Overscan,
  85.         OSCAN_STANDARD, SA_Font, &( bP->Font ), TAG_DONE );
  86.  
  87.     Wid = Scr->Width;
  88.     Hei = Scr->Height;
  89.  
  90.     SetRGB4( &(Scr->ViewPort), 0, 0L, 0L, 0L );
  91.     switch( bP->Cycle ) {
  92.     case 0:
  93.         SetRGB4( &(Scr->ViewPort), 1, vals[c1], vals[c2], vals[c3] );
  94.         break;
  95.     case 1:
  96.         SetRGB4( &(Scr->ViewPort), 1, VBeamPos()%15 + 1, VBeamPos()%15 + 1, VBeamPos()%15 + 1 );
  97.         break;
  98.     case 2:
  99.         SetRGB4( &(Scr->ViewPort), 1, 15, 15, 15 );
  100.         break;
  101.     case 3:
  102.         setCopperList( Hei, 1, &( Scr->ViewPort ));
  103.         break;
  104.     }
  105.  
  106.     numc = getTime( scrClock, bP );
  107.     while(( len = TextLength( &(Scr->RastPort), scrClock, numc )) >= Wid ) numc--;
  108.  
  109.     x = VBeamPos()%( Wid - len - 1 ) + 1;
  110.     y = VBeamPos()%( Hei - bP->Font.ta_YSize - 1 ) + 1;
  111.  
  112.     SetAPen( &(Scr->RastPort), 1 );
  113.     Move( &(Scr->RastPort), x, y + base );
  114.     Text( &(Scr->RastPort), scrClock, numc );
  115.  
  116.     BlankMousePointer();
  117.     ScreenToFront( Scr );
  118.  
  119.     while(!( SetSignal( 0L, 0L )&SIGBREAKF_CTRL_C )) {
  120.         WaitTOF();
  121.         if( !bP->Cycle ) if( !(++count%10 )) SetRGB4( &(Scr->ViewPort), 1, vals[c1 = ++c1%42],
  122.             vals[c2 = ++c2%42], vals[c3 = ++c3%42] );
  123.         numc = getTime( scrClock, bP );
  124.         while(( nlen = TextLength( &(Scr->RastPort), scrClock, numc ))+x > Wid ) numc--;
  125.         Move( &(Scr->RastPort), x, y + base );
  126.         Text( &(Scr->RastPort), scrClock, numc );
  127.         if( nlen < len ) {
  128.             SetAPen( &(Scr->RastPort), 0 );
  129.             RectFill( &(Scr->RastPort), x+nlen, y-2, x+len+2, y+bP->Font.ta_YSize+2 );
  130.             SetAPen( &(Scr->RastPort), 1 );
  131.         }
  132.         len = nlen;
  133.         if(!( count%(51-bP->Speed ))) {    
  134.             ScrollRaster( &(Scr->RastPort), dx, dy, x-2, y-2, x+len+2, y+bP->Font.ta_YSize+2 );
  135.             x -= dx; y -= dy;
  136.             if( x < 3 ) dx = -1;
  137.             else if( x > Wid-len-3 ) dx = 1;
  138.             if( y < 3 ) dy = -1;
  139.             else if( y > Hei-bP->Font.ta_YSize-3 ) dy = 1;
  140.         }
  141.     }
  142.     SetSignal( 0L, SIGBREAKF_CTRL_C );
  143.  
  144.     if( font ) CloseFont( font );
  145.     UnblankMousePointer();
  146.     CloseScreen( Scr );
  147. }
  148.